open Type
open Variable
open Lexer

(* print a boolean *)
let print_bool = function
      true -> print_string "true"
	| _ -> print_string "false"
;;

(* print an array *)
let rec print_array arr env =
	match arr with
	  [] -> print_string "[]"
	| [tail] -> print_intern [tail] env ; print_string "]"
	| head::tail -> print_intern [head] env ; print_string ", " ;
                  print_array tail env
  
(* print function *)
and print_intern expr env =
	match expr with
	  [] -> ()
	| head::tail -> begin match head with 
					  Bool(expr) -> print_bool expr
					| Int(expr) -> print_int expr
					| Float(expr) -> print_float expr
					| String(expr) -> print_string expr
					| Array(var) -> print_string "[" ; print_array var env
					| var -> (try let value = (get_var var env) in 
                   print_intern [value] env
							with NotFound -> failwith ("unknown variable :"))
					end ; 
	print_intern tail env
	
let print expr env = print_intern expr env ; print_newline ()